﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace QLTV.Forms.KeHoach
{
    public partial class frmSugestListShortPlan : BaseForm
    {
        public frmSugestListShortPlan()
        {
            InitializeComponent();
        }
        public string crewID { get; set; }
        //ngay len doi voi thuyen vien OnBoard /Xuong doi voi thuyen vien OnVacation
        public DateTime ngayLenXuong { get; set; }

        public string RankName { get; set; }
        public int RankID { get; set; }
        public int RankLower1 { get; set; }
        public int RankLower2 { get; set; }
        public int VesselID { get; set; }
        public int RankTypeID { get; set; }
        public DateTime ngaydukien { get; set; }

        private void frmSugestListShortPlan_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'dsShortPlan.tblKeHoach' table. You can move, or remove it, as needed.
            this.tblKeHoachTableAdapter.Fill(this.dsShortPlan.tblKeHoach);
            // TODO: This line of code loads data into the 'dsShortPlan.tblVessel' table. You can move, or remove it, as needed.
            this.tblVesselTableAdapter.Fill(this.dsShortPlan.tblVessel);
            // TODO: This line of code loads data into the 'dsShortPlan.tblShortPlan' table. You can move, or remove it, as needed.
            this.tblShortPlanTableAdapter.returnUndonePLan(this.dsShortPlan.tblShortPlan);
            if (RankName != "")
            {
                tadSuggestCrewList.Fill(dsShortPlan.tblSuggestCrewList, RankName, RankLower1, VesselID, RankLower2);
            }
            else
                tadSuggestCrewList.FillAll(dsShortPlan.tblSuggestCrewList);

        }

        private void simpleButton3_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            if (viewSuggestList.FocusedRowHandle > -1)
            {
                if (tblShortPlanBindingSource.Count == 0)
                {
                    string rankSelected = viewSuggestList.GetFocusedRowCellValue(colcRankName).ToString();
                    if (viewSuggestList.GetFocusedRowCellValue("cStatus").ToString() == "On Board")
                    {
                        ngayLenXuong = (DateTime)viewSuggestList.GetFocusedRowCellValue("dEmbarked");
                    }
                    else if (viewSuggestList.GetFocusedRowCellValue("cStatus").ToString() == "On Vacation")
                    {
                        ngayLenXuong = (DateTime)viewSuggestList.GetFocusedRowCellValue("dLeave");
                    }
                    else { ngayLenXuong = new DateTime(1900, 1, 1); }

                    if (RankName != "")
                    {

               

                        if (rankSelected == RankName)
                        {
                            crewID = viewSuggestList.GetFocusedRowCellValue("nCrewId").ToString();
                            this.Close();
                        }
                        else
                        {
                            if (Program.language == "en")
                            {
                                if (XtraMessageBox.Show("Rank is not compatible? Do you want to promote this crew", "Warning", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == System.Windows.Forms.DialogResult.OK)
                                {
                                    crewID = viewSuggestList.GetFocusedRowCellValue("nCrewId").ToString();
                                    this.Close();
                                }
                            }
                            else

                                if (XtraMessageBox.Show("Chức danh không phù hợp! Bạn có muốn nâng bậc cho thuyền viên này?", "Cảnh báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == System.Windows.Forms.DialogResult.OK)
                                {
                                    crewID = viewSuggestList.GetFocusedRowCellValue("nCrewId").ToString();
                                    this.Close();
                                }
                        }
                    }
                    else
                    {
                        crewID = viewSuggestList.GetFocusedRowCellValue("nCrewId").ToString();
                        this.Close();
                    }

                }
                else
                {
                    if (Program.language == "en")
                    {
                        XtraMessageBox.Show("- Currently, This crew has assigned to another plan\r\n\n- If you wish to continue, plz cancel all other plans", "Cảnh báo");
                    }
                    else
                    {
                        XtraMessageBox.Show("- Hiện tại thuyền viên này đã có trong kế hoạch khác.\r\n\n- Hãy hủy kế hoạch khác nếu bạn muốn tiếp tục", "Cảnh báo");
                    }
                }
            }



        }

        private void viewSuggestList_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
        {
            if (viewSuggestList.FocusedRowHandle > -1)
            {
                tblShortPlanBindingSource.Filter = String.Format("nCrewIDNext='{0}'", viewSuggestList.GetFocusedRowCellValue("nCrewId"));
                if (gridControl2.DataSource == null)
                    gridControl2.DataSource = tblShortPlanBindingSource;
            }
        }

        private void cmdHuy_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            if (XtraMessageBox.Show(rm.GetString("sConfirm", myCultureInfo), rm.GetString("sMessageCaption", myCultureInfo), MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
            {
                int kehoachID = Convert.ToInt32(viewKeHoach.GetFocusedRowCellValue("PlanID"));
                tblShortPlanTableAdapter.HuyKeHoach(kehoachID);
                this.tblShortPlanTableAdapter.returnUndonePLan(this.dsShortPlan.tblShortPlan);
            }
        }

        private void checkEdit1_CheckedChanged(object sender, EventArgs e)
        {
            if (checkEdit1.Checked)
                tadSuggestCrewList.FillByType(dsShortPlan.tblSuggestCrewList, VesselID);
            else
            {
                tadSuggestCrewList.Fill(dsShortPlan.tblSuggestCrewList, RankName, RankLower1, VesselID, RankLower2);
            }
        }
    }
}